import React, { useState, useEffect } from 'react'

export default function Child() {
  const [count, setCount] = useState(0)

  let a = 0 // 设置初始值
  useEffect(() => {
    let interval = setInterval(() => {
      setCount(a++)
      console.log('Child interval', a)
    }, 1000)
    console.log('Child 1', interval)
    return () => {
      clearInterval(interval)
      console.log('Child 2', interval)
    }
  }, [a])

  useEffect(() => {
    console.log('Child 1')
    window.onresize = () => {
      console.log('Child onresize')
    }
    return () => {
      window.onresize = null
      console.log('Child 2')
    }
  }, [])

  /**
   * useLayoutEffect 会阻塞页面渲染
   * 适合里面有dom 操作
   */

  return <div>Child-{count}</div>
}
